#include <cstdio>
const int max=8;
int N;
int flag[max] = {0};
int seq[max] = {0};
int print(int n)
{
    if (n == N)
    {
        for (int i = 0; i < N; ++i)
        {
            printf("%d ", seq[i]);
        }
        putchar(10);
        return 0;
    }
    int j;
    for (j = 0; j < N; ++j)
    {
        if (0 == flag[j])
        {
            seq[n] = j + 1;
            flag[j] = 1;
            print(n + 1);//每次递归调用都递进一层
            flag[j] = 0;
        }
    }
}
int main()
{
    scanf("%d", &N);
    print(0);
}